package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.hosp.bean.Result;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.utils.HttpRequestHelper;
import com.atguigu.yygh.model.hosp.Department;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author mgx
 * @version 1.0
 * @description: TODO
 * @date 2022/8/27 11:58
 */
@RestController
@RequestMapping("/api/hosp")
public class ApiDepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation(value = "删除医院科室信息")
    @PostMapping("/department/remove")
    public Result remove(HttpServletRequest request) {
        // 获取参数
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
        // 调用service方法进行删除
        departmentService.remove(paramMap);
        return Result.ok();
    }

    @ApiOperation(value = "保存医院科室信息")
    @PostMapping("/saveDepartment")
    public Result saveDepartment(HttpServletRequest request) {
        // 获取参数
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
        // 验证sign key
        // 调用service层中保存科室信息
        departmentService.saveDepartment(paramMap);
        return Result.ok();
    }

    @ApiOperation(value = "分页查询医院科室信息")
    @PostMapping("/department/list")
    public Result<Page> getDepartmentByPage(HttpServletRequest request) {
        // 获取参数
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
        // 验证signkey
        // 调用service查询方法 -- >观察apiServiceImpl中需要获取的数据：说明我们返回的data需要是一个page对象，不必手动进行map封装
        Page<Department> page = departmentService.getDepartmentPage(paramMap);
        return Result.ok(page);
    }
}
